<!DOCTYPE html>
<html lang="en" th:fragment="comments" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5"
      xmlns:th="http://www.thymeleaf.org">
<body>
<div th:if="${article}!=null">
    <div class="comment-container" th:id="${article.id ?: 0}">
        <div class="clearfix" id="comments">
            <div th:if="${article.allowComment}">
                <span class="response">
                    <form method="post" name="logoutform" th:action="@{/logout}"></form>
                    <th:block sec:authorize="isAuthenticated()">
                        Hello，<a data-no-instant="" sec:authentication="name"></a>
                        如果你想 <a href="javascript:document.logoutform.submit();">注销</a> ?
                    </th:block>
                    <th:block sec:authorize="isAnonymous()">
                        用户想要评论，请先<a data-no-instant="" th:href="@{/login}" title="登录">登录</a>!
                    </th:block>
                </span>
                <div sec:authorize="isAuthenticated()">
                    <form class="comment-form" id="comment-form" onsubmit="return TaleComment.subComment();"
                          role="form">
                        <input id="aid" name="aid" th:value="${article.id}" type="hidden"/>
                        <input th:name="${_csrf.parameterName}" th:value="${_csrf.token}" type="hidden"/>
                        <textarea class="form-control" id="textarea" maxlength="2000"
                                  minlength="5"
                                  name="text" placeholder="以上信息可以为空,评论不能为空哦!" required="required"></textarea>
                        <button class="submit" id="misubmit" type="submit">提交</button>
                    </form>
                </div>
            </div>
            <!-- 分页显示其他评论内容 -->
            <div th:if="${comments}">
                <ol class="comment-list">
                    <th:block th:each="comment :${comments.list}">
                        <li class="comment-body comment-parent comment-odd" th:id="'li-comment-'+${comment.id}">
                            <div th:id="'comment-'+${comment.id}">
                                <div class="comment-view" onclick="">
                                    <div class="comment-header">
                                        <!--设置人物头像和名称-->
                                        <img class="avatar" height="50" th:src="@{/assets/img/avatars.jpg}"/>
                                        <a class="comment-author" rel="external nofollow" th:text="${comment.author}"/>
                                    </div>
                                    <!-- 评论内容 -->
                                    <div class="comment-content">
                                        <span class="comment-author-at"></span>
                                        <p th:utext="${commons.article(comment.content)}"></p>
                                    </div>
                                    <!-- 评论日期 -->
                                    <div class="comment-meta">
                                        <time class="comment-time"
                                              th:text="${commons.dateFormat(comment.created)}"></time>
                                        <a href="javascript:void(0)"
                                           sec:authorize="isAuthenticated()"
                                           style="color: #1b961b" th:if="${comment.author}!= ${session.SPRING_SECURITY_CONTEXT.authentication.principal.username}">
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;回复
                                        </a>
                                    </div>
                                </div>
                            </div>
                        </li>
                    </th:block>
                </ol>
                <!-- 进行评论分页 -->
                <div class="lists-navigator clearfix">
                    <ol class="page-navigator">
                        <!-- 判断并展示上一页 -->
                        <th:block th:if="${comments.hasPreviousPage}">
                            <li class="prev"><a th:href="'?cp='+${comments.prePage}+'#comments'">上一页</a></li>
                        </th:block>
                        <!-- 判断并展示中间页 -->
                        <th:block th:each="navIndex : ${comments.navigatepageNums}">
                            <th:block th:if="${comments.pages} <= 5">
                                <li th:class="${comments.pageNum}==${navIndex}?'current':''">
                                    <a th:href="'?cp='+${navIndex}+'#comments'" th:text="${navIndex}"></a>
                                </li>
                            </th:block>
                            <th:block th:if="${comments.pages} > 5">
                                <li th:class="${comments.pageNum}==${navIndex}?'current':''"
                                    th:if="${comments.pageNum <=3 &&  navIndex <= 5}">
                                    <a th:href="'?cp='+${navIndex}+'#comments'" th:text="${navIndex}"></a>
                                </li>
                                <li th:class="${comments.pageNum}==${navIndex}?'current':''"
                                    th:if="${comments.pageNum >= comments.pages-2 &&  navIndex > comments.pages-5}">
                                    <a th:href="'?cp='+${navIndex}+'#comments'" th:text="${navIndex}"></a>
                                </li>
                                <li th:class="${comments.pageNum}==${navIndex}?'current':''"
                                    th:if="${comments.pageNum >=4 && comments.pageNum <= comments.pages-3 &&  navIndex >= comments.pageNum-2 && navIndex <= comments.pageNum+2}">
                                    <a th:href="'?cp='+${navIndex}+'#comments'" th:text="${navIndex}"></a>
                                </li>
                            </th:block>
                        </th:block>
                        <!-- 判断并展示下一页 -->
                        <th:block th:if="${comments.hasNextPage}">
                            <li class="next"><a th:href="'?cp='+${comments.nextPage}+'#comments'">下一页</a></li>
                        </th:block>
                    </ol>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<div th:replace="comm/tale_comment::tale_comment"></div>
</html>